﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Site
{
    public partial class MobileSetup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sResponse = "Invalid Parameters";

            string sPID = Request.QueryString["PID"];
            string sWID = Request.QueryString["WID"];

            if (sPID != null && sWID != null)
            {
                SqlDataSource1.SelectCommand = "SELECT WID FROM Workers WHERE WID='" + sWID + "'";
                DataView View = (DataView)SqlDataSource1.Select(new DataSourceSelectArguments());
                if (View.Count != 1)
                    sResponse = "Worker Not Found!";
                else
                {
                    SqlDataSource1.SelectCommand = "SELECT PID FROM Workers WHERE PID='" + sPID + "' AND WID='" + sWID + "'";
                    View = (DataView)SqlDataSource1.Select(new DataSourceSelectArguments());
                    if (View.Count != 1)
                        sResponse = "Phone not registered to worker or not found";
                    else
                    {
                        sResponse = "200 OK";
                    }
                }
            }
                

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "text/plain";
            Response.Write(sResponse);
            Response.End();
        }
    }
}